﻿#region Copyright (c) 2010 R. Uittenbosch
/*
* Copyright (C) 2010 R. Uittenbosch
* 
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 
* associated documentation files (the "Software"), to deal in the Software without restriction, including 
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
* copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the 
* following conditions:
* 
* The above copyright notice and this permission notice shall be included in all copies or substantial 
* portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 
* EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 
* USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#endregion

using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using TouchUI.System.Mobile.Mvc;
using System.Mobile.Mvc;

using TouchUI;
using LinkedService.Mobile.ServiceEntities;
using System.Drawing;
using System.Windows.Forms;

namespace LinkedIn.Mobile
{

  /// <summary>
  /// Dialog for showing the users profile
  /// </summary>
  public class ProfileDialog : ViewDialog, IView<LinkedService.Mobile.ServiceEntities.Person>
  {

    [PublishEvent("OnBack")]
    public event EventHandler OnBackEvent;

    /// <summary>
    /// Everyting is just in one big scrollpanel
    /// </summary>
    private ProfileDetailScrollPanel detailScrollPanel;

    public ProfileDialog()
    {
      ScreenFactor      = Common.Instance.ScreenFactor;
      Rectangle         = Common.Instance.ClientRectangle;
      detailScrollPanel = new ProfileDetailScrollPanel();
    }

    public override void Paint(Graphics g)
    {
      g.Clear(BackColor);
      // Let the scrollpanel do its painting
      detailScrollPanel.Paint(g);
    }

    /// <summary>
    /// Propagate
    /// </summary>
    /// <param name="p"></param>
    public override void MouseDown(Point p)
    {
      detailScrollPanel.MouseDown(new Point(p.X, p.Y ));
    }

    /// <summary>
    /// Propagate
    /// </summary>
    /// <param name="p"></param>
    public override void MouseMove(Point p)
    {
      detailScrollPanel.MouseMove(new Point(p.X, p.Y ));
     
    }

    /// <summary>
    /// Propagate
    /// </summary>
    /// <param name="p"></param>
    public override void MouseUp(Point p)
    {
      detailScrollPanel.MouseUp(new Point(p.X, p.Y ));
      // Horizontal move?
      if (detailScrollPanel.HorizontalGesture > 0)
      {
        if (OnBackEvent != null)
          OnBackEvent(this, EventArgs.Empty);
      }
    }

    /// <summary>
    /// Propagate
    /// </summary>
    /// <param name="e"></param>
    public override void KeyDown(KeyEventArgs e)
    {
      detailScrollPanel.KeyDown(e);
    }

    /// <summary>
    /// Propagate
    /// </summary>
    /// <param name="e"></param>
    public override void KeyUp(KeyEventArgs e)
    {
      detailScrollPanel.KeyUp(e);
    }

    /// <summary>
    /// Propagate
    /// </summary>
    /// <param name="r"></param>
    public override void Resize(Rectangle r)
    {
      this.Rectangle = r;
      detailScrollPanel.Resize(r);
    }

    private void OnProfileLoaded(object sender, EventArgs e)
    {
      detailScrollPanel.User = this.Model;
    }

    #region IView<LinkedService.Mobile.ServiceEntities.Connections> Members

    public new ViewDataDictionary<LinkedService.Mobile.ServiceEntities.Person> ViewData
    {
      get;
      set;
    }

    public new LinkedService.Mobile.ServiceEntities.Person Model
    {
      get
      {
        return this.ViewData.Model;
      }
      set
      {
        this.ViewData.Model = value;
      }
    }

    #endregion
  }
}
